<!--  活动列表组件  -->
<template>
  <div>
    <div class="">
      <h2>学习活动列表</h2>
      <el-table
        :loading="listLoading"
        :data="list.slice((this.currentPage-1)*pagesize,currentPage*pagesize)"
        element-loading-text="Loading"
        border
        fit
        highlight-current-row
      >
        <el-table-column
          align="center"
          prop="actId"
          label="活动编号"
          width="100px"
        />

        <el-table-column
          align="center"
          prop="actTitle"
          label="活动标题"
          width="200px"
        />

        <el-table-column
          align="center"
          prop="actType"
          label="活动类型"
          width="100px"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.actType=='0'">学习</span>
            <span v-if="scope.row.actType=='1'" style="color: blue;"><b>娱乐</b></span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="actLimit"
          label="活动人数"
          width="100px"
        />

        <el-table-column
          align="center"
          prop="actHost"
          label="活动发起者"
          width="120px"
        />

        <el-table-column
          align="center"
          prop="actAddress"
          label="活动地点"
          width="300px"
        />

        <!-- <el-table-column
          align="center"
          prop="actMemberWay"
          label="录取方式"
          width="100px"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.actMemberWay=='1'">手动审核</span>
            <span v-if="scope.row.actMemberWay=='2'">无需审核</span>
          </template>
        </el-table-column> -->

        <el-table-column
          align="center"
          prop="actStatus"
          label="活动状态"
          width="100px"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.actStatus=='0'">审核中</span>
            <span v-if="scope.row.actStatus=='1'">审核通过</span>
            <span v-if="scope.row.actStatus=='2'">审核不通过</span>
            <span v-if="scope.row.actStatus=='3'">报名中</span>
            <span v-if="scope.row.actStatus=='4'">报名截止</span>
            <span v-if="scope.row.actStatus=='5'">活动结束</span>
          </template>
        </el-table-column>

        <el-table-column align="center" label="操作">
          <template slot-scope="Scope">
            <el-button type="warning" icon="el-icon-edit" size="mini" @click="delete_study(Scope.row.actId)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div id="pages">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[10]"
          :page-size="pagesize"
          layout="total, sizes,prev, pager, next"
          :total="list.length"
          prev-text="上一页"
          next-text="下一页"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
    <activity-info ref="info" :act-id="actId" :show="show" />
  </div>

</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import { getAllActivitybyActPartId1, delete_study } from '../../api/act.js'
import Info from '../../components/activity/info.vue'

export default {
  name: '',
  // import引入的组件需要注入到对象中才能使用
  components: {
    'activity-info': Info
  },
  props: {

    type: String
  },
  data() {
    // 这里存放数据
    return {
      actId: '',
      show: false,
      dialogFormVisible: false,
      search: {},
      listLoading: false,
      list: [],
      currentPage: 1, // 默认显示页面为1
      pagesize: 10 //    每页的数据条数
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getPartActivity()
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {},
  // 方法集合
  methods: {
    // 每页下拉显示数据
    handleSizeChange(size) {
      this.pagesize = size
    },
    // 点击第几页
    handleCurrentChange(currentPage) {
      console.log(this)
      this.currentPage = currentPage
    },
    handleClick(row) {
      console.log(row)
    },

    getPartActivity() {
      getAllActivitybyActPartId1().then((data) => {
        this.list = data.obj
        this.listLoading = false
      })
    },

    getActivityInfo(actId) {
      this.$refs.info.showInfo(actId)
    },

    delete_study(actId) {
      console.log('删除的id为：', actId)
      delete_study(actId).then((data) => {
        this.$message({
          showClose: true,
          message: '删除成功',
          type: 'success'
        })
        location.reload()
      })
    }

  } // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style scoped>

</style>
